<style>
@media (min-width: 1200px){
    .col-lg-1 {
        width: 7.5%;
    }  
}
</style>
{include file="material/_date" /}
<input type="hidden" name="platform_ids" value="{:input('get.platform_ids')}">
<div class="col-sm-12 col-md-4 col-lg-2">
    <input type="text" class="form-control" name="keyword" value="{$keyword|default=''}" placeholder="请输入关键字搜索">
</div>

<div class="col-sm-12 col-md-1" style="width: 59px;">
    <button class="btn btn-primary" type="submit">搜索</button>
</div>

<!-- 工作台只显示下级员工 -->
{if stristr($action,'mycenter') }
<div class="col-sm-12 col-lg-1">
    <select name="uid" id="uid" class="form-control">
        <option value="0">全部工号</option>
        {foreach name="userlist2" item="vo" key="k" }
        <option value="{$k}" {if input('get.uid')==$k}selected {/if}>{$vo}</option>
        {/foreach}
    </select>
</div>
{else/}
<!-- 公众库显示全部员工 -->
<div class="col-sm-12 col-lg-1">
    <select name="uid" id="uid" class="form-control">
        <option value="0">全部工号</option>
        {foreach name="userlist" item="vo" key="k" }
        <option value="{$k}" {if input('get.uid')==$k}selected {/if}>{$vo}</option>
        {/foreach}
    </select>
</div>
{/if}

<div class="col-sm-12 col-lg-1">
    <select name="channel" id="channel" class="form-control">
        <option value="999999">频道</option>
        <option value="1" {if input('get.channel')==1}selected {/if}>男频</option>
        <option value="2" {if input('get.channel')==2}selected {/if}>女频</option>
    </select>
</div>

<div class="col-sm-12 col-lg-1">
    <select name="category_id" id="category_id" class="form-control">
        <option value="0">小说分类</option>
        {foreach name="dataArr['category_id']" item="vo" key="k" }
        <option value="{$vo.id}" {if input('get.category_id')==$vo['id']}selected {/if} >{$vo.name}</option>
        {/foreach}
    </select>
</div>

<div class="col-sm-12 col-lg-1">
    <select  id="pub_sort" class="form-control">
        <option value="1" {if input('get.pub_sort')=='1'}selected {/if}>按时间排序</option>

        
        <option value="4" {if input('get.pub_sort')=='4'}selected {/if}>复制从高到低</option>
        <option value="5" {if input('get.pub_sort')=='5'}selected {/if}>复制从低到高</option>
        {if $action != 'wenan-mycenter_1_1'}
        <option value="2" {if input('get.pub_sort')=='2'}selected {/if}>评分从高到低</option>
        <option value="3" {if input('get.pub_sort')=='3'}selected {/if}>评分从低到高</option>

        <option value="6" {if input('get.pub_sort')=='6'}selected {/if}>加入从高到低</option>
        <option value="7" {if input('get.pub_sort')=='7'}selected {/if}>加入从低到高</option>

        <option value="8" {if input('get.pub_sort')=='8'}selected {/if}>量级从高到低</option>
        <option value="9" {if input('get.pub_sort')=='9'}selected {/if}>量级从低到高</option>

        <option value="10" {if input('get.pub_sort')=='10'}selected {/if}>书名从高到低</option>
        <option value="11" {if input('get.pub_sort')=='11'}selected {/if}>书名从低到高</option>

        {/if}
    </select>
</div>


<!-- 只有工作台下-抖音才能选择模板 -->
{if $action == 'wenan-mycenter_1_1' && $platform_id == 3}
<div class="col-sm-12 col-lg-1">
    <select name="mb" id="mb" class="form-control">
        <option value="1" {if $mb=='1'}selected {/if}>中图标排列</option>
        <option value="2" {if $mb=='2'}selected {/if}>小图标排列</option>
        <option value="3" {if $mb=='3'}selected {/if}>大图标排列</option>
    </select>
</div>
{/if}

<script>
    $(() => {
        function objectToQuery() {
            let obj = arguments[0];
            let prefix = arguments[1];
            if (typeof obj !== "object") return "";
            const attrs = Object.keys(obj);
            return attrs.reduce((query, attr, index) => {
                // 判断是否是第一层第一个循环
                if (index === 0 && !prefix) query += "?";
                if (typeof obj[attr] === "object") {
                    const subPrefix = prefix ? `${prefix}[${attr}]` : attr;
                    query += this.objectToQuery(obj[attr], subPrefix);
                } else {
                    if (prefix) {
                        query += `${prefix}[${attr}]=${obj[attr]}`;
                    } else {
                        query += `${attr}=${obj[attr]}`;
                    }
                }
                // 判断是否是第一层最后一个循环
                if (index !== attrs.length - 1) query += "&";
                return query;
            }, "");
        }
        function goUrl(params){
            let {
                uid = $('#uid option:selected').val(),
                channel = $('#channel option:selected').val(),
                category_id = $('#category_id option:selected').val(),
                pub_sort = $('#pub_sort option:selected').val(),
                mb = $('#mb option:selected').val() ?? '',
                keyword = '{$keyword}',
                startdata = '{$startdata}',
                enddata = '{$enddata}'
            } = params
            window.location.href = objectToQuery({
                uid,
                channel,
                category_id,
                pub_sort,
                mb,
                keyword,
                startdata,
                enddata
            })
        }
        $('#uid').change(() => {
            goUrl({})
        });
        $('#channel').change(() => {
            goUrl({})
        });
        $('#category_id').change(() => {
            goUrl({})
        });
        //下拉排序
        $('#pub_sort').change(() => {
            var pub_sort = $('#pub_sort option:selected').val();
            goUrl({})
        });

        $('#mb').change(() => {
            goUrl({})
        });

    });

</script>